package com.hskn.hss.module.file.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.file.service.IFileService;
import com.hskn.hss.utils.OssUtils;
import com.hskn.hss.utils.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hskn
 * @since 2021-04-30
 */
@Service
public class FileServiceImpl implements IFileService {

    @Override
    public String upload(JSONObject params) throws HssException {
        String base64 = params.getString("base64");
        String fileName = params.getString("fileName");
        if (StringUtils.isEmpty(base64) || StringUtils.isEmpty(fileName) || !fileName.contains(".")) {
            throw new HssException("参数错误");
        }
        String url = OssUtils.upFile(base64, fileName);
        return url;
    }

    @Override
    public String uploadFile(MultipartFile multipartFile) throws HssException, IOException {
        String url = OssUtils.uploadFile(multipartFile);
        return url;
    }

}
